#!/bin/sh

nr_threads=${1%%[a-z]*}

if [ "${nr_threads%%%}" != "$nr_threads" ]; then
	nr_threads=${nr_threads%%%}
	div=100
	if [ "${nr_threads#*.[0-9]}" != "$nr_threads" ]; then
		decimal_digits=${nr_threads#*.}
		integer_digits=${nr_threads%.*}
		integer_digits=${integer_digits#0}
		nr_threads="$integer_digits$decimal_digits"
		i=0
		while [ $i -lt ${#decimal_digits} ]
		do
			div="${div}0"
			i=$((i + 1))
		done
	fi
	nr_threads=$((nr_threads * nr_cpu / div + 1))
fi

cat >> $TMP/env.yaml <<EOF
$(basename $0): $nr_threads
EOF
